package com.fick.struts.action;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fick.hibernate.dao.ChannelDAO;
import com.fick.hibernate.dao.VodDAO;
import com.fick.hibernate.dao.VodServerDAO;
import com.fick.hibernate.dao.VodsDAO;
import com.fick.hibernate.model.Admin;
import com.fick.hibernate.model.Channel;
import com.fick.hibernate.model.Vod;
import com.fick.hibernate.model.VodServer;
import com.fick.hibernate.model.Vods;
import com.fick.tools.SystemLogger;
/**
 * 视频分集管理
 * add by 王浩强
 * 2009-08-29
 * */
public class VodsAction extends DispatchAction {

	private VodsDAO dao=new VodsDAO();
	public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		String seq=request.getParameter("seq");
		String path=request.getParameter("path");
		String vodid=request.getParameter("vodid");
		String vodsid=request.getParameter("vodsid");
		try {
			if (path!=null && path.trim().length()>0) {
				if (vodsid!=null&&vodsid.trim().length()>0) {
					//修改操作
					Vods vods=dao.findById(Integer.parseInt(vodsid));
					if (vods!=null) {
						vods.setPath(path);
						dao.update(vods);
					}
				}else {
					Vod vod=new VodDAO().findById(Integer.parseInt(vodid));
					Vods vods=new Vods();
					vods.setPath(path);
					vods.setSeq(Integer.parseInt(seq));
					vods.setVod(vod);
					dao.save(vods);
				}
			}else {
				if (vodsid!=null&&vodsid.trim().length()>0) {
					//如果path为空则删除操作
					Vods vods=dao.findById(Integer.parseInt(vodsid));
					if (vods!=null) {
						dao.delete(vods);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapping.findForward("show");
	}

	public ActionForward delById(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		String id=request.getParameter("id");
		if (id!=null && id.trim().length()>0) {
			Vods vods=dao.findById(Integer.parseInt(id));
			if (vods!=null) {
				dao.delete(vods);
			}
		}
		return mapping.findForward("show");
	}
}
